package com.dx.wlmq.controller;

import com.alibaba.fastjson.JSON;
import com.dx.wlmq.domain.SmbmsRole;
import com.dx.wlmq.service.SmbmsRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName SmbmsRoleController
 * @Description TODO:
 * @Author 12994
 * @Date 2024/10/20 19:07
 * @Version 1.0
 **/
@Controller
@RequestMapping("/smbmsRole")
public class SmbmsRoleController {

    @Autowired
    @Qualifier("smbmsRoleService")
    private SmbmsRoleService smbmsRoleService;

    // 查询所有角色列表
    @RequestMapping(value = "/listAllRole", method = RequestMethod.GET, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String listAllRole(HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString(smbmsRoleService.listAllRole());
    }

    // 通过id查询角色
    @RequestMapping(value = "/findRoleById", method = RequestMethod.GET, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String findRoleById(Long id, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString(smbmsRoleService.findRoleById(id));
    }

    // 增加一个角色
    @RequestMapping(value = "/addRole", method = RequestMethod.POST, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String addRole(@RequestBody SmbmsRole role, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("添加了" + smbmsRoleService.addRole(role) + "条记录!");
    }

    // 通过id删除一个角色
    @RequestMapping(value = "/deleteRoleById", method = RequestMethod.DELETE, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String deleteRoleById(@RequestBody Long id, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("删除了" + smbmsRoleService.deleteRoleById(id) + "条记录!");
    }

    // 更新一个角色
    @RequestMapping(value = "/updateRole", method = RequestMethod.PUT, produces = "application/json; charset=utf-8;")
    @ResponseBody
    public String updateRole(@RequestBody SmbmsRole role, HttpServletResponse response) {
        response.setContentType("application/json; charset=utf-8;");
        return JSON.toJSONString("更新了" + smbmsRoleService.updateRole(role) + "条记录!");
    }
}
